package com.warm.test.satoken;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.warm.core.domain.R;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.validation.annotation.Valid;

/**
 * 注解鉴权测试
 *
 * @author warm
 */
@Valid
@Controller
@Mapping("/demo/auth/")
public class CheckAuthController {

    /**
     * 登录认证，登录之后才可以进入方法 ---- http://localhost:18080/auth/checkLogin
     *
     * @return
     */
    @SaCheckLogin
    @Mapping("checkLogin")
    public R checkLogin() {
        return R.ok();
    }

    // 权限认证，具备user-add权限才可以进入方法 ---- http://localhost:18080/demo/auth/checkPermission
    @SaCheckPermission("user-add")
    @Mapping("checkPermission")
    public R checkPermission() {
        return R.ok();
    }

    // 权限认证，同时具备所有权限才可以进入 ---- http://localhost:18080/demo/auth/checkPermissionAnd
    @SaCheckPermission({"user-add", "user-delete", "user-update"})
    @Mapping("checkPermissionAnd")
    public R checkPermissionAnd() {
        return R.ok();
    }

    // 权限认证，只要具备其中一个就可以进入 ---- http://localhost:18080/demo/auth/checkPermissionOr
    @SaCheckPermission(value = {"user-add", "user-delete", "user-update"}, mode = SaMode.OR)
    @Mapping("checkPermissionOr")
    public R checkPermissionOr() {
        return R.ok();
    }

    // 角色认证，只有具备admin角色才可以进入 ---- http://localhost:18080/demo/auth/checkRole
    @SaCheckRole("admin")
    @Mapping("checkRole")
    public R checkRole() {
        return R.ok();
    }

}
